package com.shuoyue.adven.broadcast;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;

import com.shuoyue.adven.init.LauncherActivity;

public class TurnOnBroadcastReceiver extends BroadcastReceiver {
    /**
     * 接收广播消息后都会进入 onReceive 方法，然后要做的就是对相应的消息做出相应的处理
     *
     * @param context 表示广播接收器所运行的上下文
     * @param intent  表示广播接收器收到的Intent
     */
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.i("Wmx logs::", intent.getAction());
//        Toast.makeText(context, intent.getAction(), Toast.LENGTH_LONG).show();

        /**
         * 如果 系统 启动的消息，则启动 APP 主页活动
         */
        String action = intent.getAction().toString();
        if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
            Intent intentMainActivity = new Intent(context, LauncherActivity.class);
            intentMainActivity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intentMainActivity);
            Toast.makeText(context, "开机完毕~", Toast.LENGTH_LONG).show();
////            //设置关机和开机时间,此处每次开机设置下次的计划,已被周期计划替代
//            Calendar calendar = Calendar.getInstance();
//            calendar.setTime(new Date());
//            //关机时间:晚上0点
//            calendar.add(Calendar.DAY_OF_MONTH, 1);
//            //开机时间:隔日早上6点
//            int year = calendar.get(Calendar.YEAR);
//            int mouth = calendar.get(Calendar.MONTH);
//            int day = calendar.get(Calendar.DAY_OF_MONTH);
////            int   mHour=calendar.get(Calendar.HOUR);
////            int   mMinute=calendar.get(Calendar.MINUTE);
//            int[] timeoffArray = new int[]{year, mouth, day, 23, 30};//下次关机时间
//            int[] timeonArray = new int[]{year, mouth, day, 23, 35};//下次开机时间
////            int[] timeoffArray = new int[]{2020, 12, 4, 21, 50};//下次关机时间
////            int[] timeonArray = new int[]{2020, 12, 4, 21, 55};//下次开机时间
//            PowerUtil.setPowerOneTime(context, timeonArray, timeoffArray);
        }
    }
}